package ui;

import services.WarehousingServicempl;
import vo.Sale;
import vo.Warehousing;

import java.util.List;
import java.util.Scanner;

public class WarehousingLogin {
    static WarehousingServicempl warehousingServicempl=new WarehousingServicempl();//获取操作入库表的具体类对象
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){ //入库表页面
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
                break;
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
                break;
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
                break;
            case 4:
                Warehousing warehousing =getcustombyid();
                System.out.println(warehousing);
                break;
            case 5:
                List<Warehousing> list=getall();
                for(Warehousing warehousing1:list){
                    System.out.println(warehousing1);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }

    private static boolean add() {
        System.out.println("请输入入库的家具的编号");
        int id=scanner.nextInt();
        System.out.println("请输入入库的家具的数量");
        int count=scanner.nextInt();
        System.out.println("请输入入库的家具的时间");
        String time=scanner.nextLine();
        Warehousing warehousing=new Warehousing(id,count,time);
        return warehousingServicempl.add(warehousing);
    }

    private static boolean delet() {
        System.out.println("请输入入库的家具的编号");
        int id=scanner.nextInt();
        Warehousing warehousing=new Warehousing(id);
        return warehousingServicempl.delete(warehousing);
    }

    private static boolean modify() {
        System.out.println("请输入入库的家具的编号");
        int id=scanner.nextInt();
        System.out.println("请输入入库的家具的数量");
        int count=scanner.nextInt();
        System.out.println("请输入入库的家具的时间");
        String time=scanner.nextLine();
        Warehousing warehousing=new Warehousing(id,count,time);
       return warehousingServicempl.modify(warehousing);
    }

    private static Warehousing getcustombyid() {
        System.out.println("请输入入库的家具的编号");
        String  id=scanner.nextLine();
       return warehousingServicempl.getcustombyid(id);
    }

    private static List<Warehousing> getall() {
        return warehousingServicempl.getall();
    }
}
